package com.xxl.job.admin.dao.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ibm.risk.common.dao.JpaDAO;
import com.xxl.job.admin.core.model.JobGroup;
import com.xxl.job.admin.dao.IJobGroupDao;

/**
 * Created by xuxueli on 16/9/30.
 */
@Repository
@Transactional(readOnly = true)
public class JobGroupDaoImpl implements IJobGroupDao {

	@Inject
	JpaDAO jpaDAO;

    @Override
    public List<JobGroup> findAll() {
		return jpaDAO.createNamedQuery(JobGroup.QUERYALL, JobGroup.class).getResultList();
    }

    @Override
	@Transactional(readOnly = false)
	public int save(JobGroup jobGroup) {
		jpaDAO.persist(jobGroup);
		return 1;
    }

	@Override
	@Transactional(readOnly = false)
	public int update(JobGroup jobGroup) {
		jpaDAO.merge(jobGroup);
		return 1;
    }

	@Override
	@Transactional(readOnly = false)
	public int remove(Long id) {
		jpaDAO.remove(jpaDAO.getReference(JobGroup.class, id));
		return 1;
    }

    @Override
	public JobGroup load(Long id) {
		return jpaDAO.find(JobGroup.class, id);
    }


}
